草庐IT

c++ - auto_ptr 和 dynamic_pointer_cast

全部标签

pointers - Go函数指针问题

这个问题在这里已经有了答案:MyobjectisnotupdatedevenifIusethepointertoatypetoupdateit(3个答案)GolangOperatorOverloading(1个回答)Golangchangingvaluesofastructinsideamethodofanotherstruct(2个答案)CopyinstancesoftypeT,whenanyofthemethodsofanamedtypeThaveapointerreceiver(1个回答)关闭5年前。我有一个结构typekeeperstruct{ptrint32}然后我给它添加一

pointers - Go 中的指针解除引用是如何工作的?

我正在http://tour.golang.org/学习golang教程,并在example29中尝试了一些东西为了方便大家引用,原例子复制在这里:packagemainimport"fmt"typeVertexstruct{X,Yint}var(p=Vertex{1,2}//hastypeVertexq=&Vertex{1,2}//hastype*Vertexr=Vertex{X:1}//Y:0isimplicits=Vertex{}//X:0andY:0)funcmain(){fmt.Println(p,q,r,s)}它非常基础,展示了如何创建这个奇特的新结构Vertex的实例。E

golang 中的 C long double

我正在将算法从C移植到Go。我有点困惑。这是C函数:voidgauss_gen_cdf(uint64_tcdf[],longdoublesigma,intn){inti;longdoubles,d,e;//Calculations...for(i=1;i并在for循环中将值“s”分配给数组cdf中的元素“x”。这怎么可能?据我所知,longdouble是float64(在Go上下文中)。所以我不应该能够编译C代码,因为我正在将一个longdouble分配给一个只包含uint64元素的数组。但C代码运行良好。那么有人可以解释为什么这是有效的吗?非常感谢。更新:函数的原始C代码可以在这里找

pointers - 指向方法参数中接口(interface)的指针?

Gistwithcode如何在第30行使用接口(interface)Herbivore代替*Mouse?我想将实现Herbivore接口(interface)的不同结构传递给方法eatingVictim,而不仅仅是Mouse 最佳答案 让我解释一下:首先在这个函数中:func(predatorCat)eatingVictim(victim*Mouse){fmt.Println(predator.name+"'seatingvictim"+victim.name)predator.hungry=falsevictim.alive=fa

pointers - 隐藏 nil 值,理解为什么 golang 在这里失败

我不明白如何正确确保某些东西不是nil在这种情况下:packagemaintypeshowerinterface{getWater()[]shower}typedisplaystruct{SubDisplay*display}func(ddisplay)getWater()[]shower{return[]shower{display{},d.SubDisplay}}funcmain(){//SubDisplaywillbeinitializedwithnulls:=display{}//water:=[]shower{nil}water:=s.getWater()for_,x:=ra

c - 如何从 Go 函数返回 C 指针?

我有疑问是否可以从C上的Go函数指针返回?例如main.c可以是:structopen_db_returndb_ptr=open_db(db_path);GoSlicebacket={"DB",2,2};GoSlicekey={"CONFIG",6,6};structget_value_returnval=get_value(db_ptr.r0,backet,key);close_db(db_ptr.r0);接下来是Go代码://exportopen_dbfuncopen_db(pathstring)(interface{},error){db,err:=db.Open(path,06

pointers - 在 Go 中使用类似的指针结构分配结构

我有两个相似的结构,我想将一个分配给另一个。第一个“Equipment”是用来匹配数据库的结构。第二个“JsonEquipment”是解析JSON数据的辅助结构。例子如下:typeEquipmentstruct{IDuintCategoryIDuintIpstringLoginstringPasswordstring}typeJsonEquipmentstruct{ID*uintCategory*stringIp*stringLogin*stringPassword*string}指针用于检查该字段是否存在于JSON中。更多信息:Howtorecognizevoidvalueandun

不能用宏包装 cgo 标志

我编写了一个Go程序来模拟按键操作。为此,我必须使用cgo和不同的C代码片段,具体取决于正在编译Go代码的操作系统。我编写的代码如下所示:packagekeyboard/*#include#ifdef__WIN32#cgoCFLAGS:-nostdlib#includevoidSetKey(uint16_tkey,uint8_tvalue){INPUTip;ip.type=INPUT_KEYBOARD;ip.ki.wScan=0;ip.ki.time=0;ip.ki.dwExtraInfo=0;ip.ki.wVk=key;if(value){ip.ki.dwFlags=0;}else{

c - 如何在没有定义 main() 的情况下让 cgo 构建目标文件?

我有一个完全用C编写的项目。我只需要调用一个必须用GO编写的函数。因此,我使用cgo构建C文件,然后我想使用生成的目标文件与我的主C项目链接。假设我有一个文件foo.go和一个函数funcHelloWorld()。我希望从我的C代码中执行此函数。所以我做了以下步骤#gotoolcgofoo.go#cd_obj&&gcc-c*.o现在我有两个文件:#_cgo_export.o_cgo_main.o但是,main()以某种方式在那里定义,我无法将这些目标文件与我的主项目(多个主项目)链接。我如何让cgo不放入虚拟main?还是我这样做完全错了?编辑我需要入口点在C中。其他人发布的建议要求入

objective-c - cgo godefs 和 Objective-C

我通过CGoLang的包在GoLang上编写了一个包含Objective-C代码(调用一些OSXAPI)的程序,我需要从Go传递类型为T的变量代码到Objective-C代码,反之亦然。T是结构(或其他类型)。所以我需要在GoLang中创建兼容的(在内存布局方面)类型/变量,并通过unsafe.Pointer转换将其传递给Objective-C。对于通用C代码,我在这种情况下使用godefs,但我无法将godefs用于Objective-C。如果我尝试gotoolcgo-godefscgodefs.go//Thisis"cgodefs.go"filepackagetmp/*#cgoCF